<?php
/**
 * Created by PhpStorm.
 * User: 87393
 * Date: 2019-02-25
 * Time: 15:36
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Util\ResultsVo;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class UploadController extends Controller {


    public function upload(Request $request) {

        $time = Carbon::now()->getTimestamp();

        $file = 'photo';

        $path = $request->file($file)->store(
            date('Y', $time).'-'.date('m', $time), 'uploads'
        );

        $data['url'] = config('app.url').'/uploads/'.$path;

        return response()->json(new ResultsVo(['data'=>$data,'message'=>Lang::get("response.success")]));
    }

    public function uploadArticle(Request $request){

        $time = Carbon::now()->getTimestamp();

        $path = $request->file('imgFile')->store(
            date('Y', $time).'-'.date('m', $time), 'uploads'
        );
        $data['error'] = 0;
        $data['url'] = config('app.url').'/uploads/'.$path;

        return response()->json($data);
    }


}